<?php
if (! defined ( 'BASEPATH' ))
	exit ( 'No direct script access allowed' );

class referral extends CI_Controller {
	function __construct() {
		parent::__construct ();
		$this->load->helper ( 'url' );
		$this->load->model ( 'friendsreferral_model' );
		$this->load->model ( 'user_model' );
		$this->load->library ( 'code_fragment' );
		$this->load->model ( 'usertouser_model' );
	}
	function getFridensList() {
		//$data=$_POST;
		$array = $this->friendsreferral_model->queryFriendsList ( $_POST );
		echo json_encode ( $array );
	}
	function addReferral() {
		$rs=$this->user_model->queryOneUserInfo($_POST);
		$_POST['perserteeName']=$rs["nickName"];
		$data = json_encode ( $this->friendsreferral_model->addReferral ( $_POST ) );
		echo $data;
	}
	function userTsHytj() {
		$data=$this->friendsreferral_model->getRefreralInfo(array("userId"=>$this->session->userdata("userId")));
		$this->load->view("public_view/user_ts_hytj",array("ts_hytj"=>$this->code_fragment->tsHytj($data)));
	}
	function addFriends(){
		$affectedRow=$this->friendsreferral_model->updateFriendsreferral($_POST);
		$msg="操作成功";
		if($affectedRow==0){
			$msg="系统繁忙，请稍后再试";			
		}else{
			if(intval($_POST["referralStatus"])==1){
				$row=$this->friendsreferral_model->getReferralUserInfo($_POST);
				if(empty($row)){
					$msg="操作失败";
				}else{
					$this->usertouser_model->addUserToUser($row);
				}
			}
		}		
		echo $msg;
	}
}
?>